package org.dizem.intellipainter.component.tool;

import org.dizem.intellipainter.model.ToolType;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

/**
 * User: dizem@126.com
 * Time: 12-2-18 下午6:12
 */
public class ToolButton extends JToggleButton {
	private final ToolType toolType;
	private static final Dimension SIZE = new Dimension(50, 35);
	private static final Font font = new Font("微软雅黑", Font.PLAIN, 13);

	public ToolButton(final ToolType toolType, final ToolSelectCallback callback) {
		this.toolType = toolType;
		setDoubleBuffered(true);

		addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				callback.onSelectTool(toolType);
			}
		});

	}

	@Override
	public void paint(Graphics g) {
		super.paint(g);
		g.setFont(font);
		Graphics2D g2d = (Graphics2D) g;
		RenderingHints qualityHints = new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
		qualityHints.put(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
		g2d.setRenderingHints(qualityHints);
		g.drawString(toolType.getText(), 12, 22);

	}

	@Override
	public Dimension getPreferredSize() {
		return SIZE;
	}

	public ToolType getToolType() {
		return toolType;
	}
}
